package day01.file;

import java.io.File;
import java.io.FileFilter;

/**
 * @ClassName ListFilesDemo2
 * @Description TODO
 * @Author 16433
 * @Date 2023/3/6 16:53
 * @Version 1.0
 *
 * 获取满足条件的所有子项,用到文件过滤器
 **/
public class ListFilesDemo2 {
    public static void main(String[] args) {
        /*获取file目录下名字带s的所有子项*/
        //定义过滤器
        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                String name = pathname.getName();
                return name.contains("s");
            }
        };
        //将过滤器传给listFiles()方法,获取名字带s的所有子项
        File dir = new File("./JSD2205_SE/src/day01/file");
        if(dir.isDirectory()){
            File[] subs = dir.listFiles(filter);
            for (int i = 0; i < subs.length; i++) {
                System.out.println(subs[i].getName());
            }
        }
    }
}
